layui.use(['form','layer','laydate'], function() {

    var $ = layui.$
        ,form = layui.form
        ,laydate = layui.laydate;

    //日期
    laydate.render({
        elem: '#depart_at'
        ,type: 'date'
        ,range:true
    });

    //日期
    laydate.render({
        elem: '#rule_at'
        ,type: 'date'
        ,range:true
    });

    /**
     * 添加一行rule
     */
    $('.rule-add').on('click',function (param) {
        var tr = '<tr>'+
            '<td><select name="rule_type[]">'+
            '<option value="1">成人</option>'+
            '<option value="2">儿童</option>'+
            '<option value="3">婴儿</option>'+
            '</select></td>'+
            '<td> <input type="text" name="rebate_price[]" placeholder="￥" autocomplete="off" class="layui-input"></td>'+
            '<td><input type="text" name="rebate_percentage[]" placeholder="%" autocomplete="off" class="layui-input"></td>'+
            '<td><input type="text" name="biding_price[]" placeholder="￥" autocomplete="off" class="layui-input"></td>'+
            '<td><input type="text" name="biding_percentage[]" placeholder="%" autocomplete="off" class="layui-input"></td>'+
            '<td><input type="text" name="freight_min[]" placeholder="￥" autocomplete="off" class="layui-input"></td>'+
            '<td><input type="text" name="freight_max[]" value="9999" placeholder="￥" autocomplete="off" class="layui-input"></td>'+
            '<td> <a href="#" class="rule-del"> <i class="layui-icon layui-icon-delete"></i></a></td>'+
            '</tr>';

        $('#rule-table').append(tr);
        form.render("select");
    });

    /**
     * 删除一行rule
     */
    $('.layui-icon-delete').on('click',function (param) {
        $(this).parent().parent().hide();
    });

    /**
     * 产品选择
     */
    form.on('select(product-type)',function (data){

        $('.product-type-item').hide();

        switch (data.value) {

            case '30':
            case '31':
            case '36':{

                $('#qn-product-mark').show();
                break;
            }
            case '40': {

                $('#tc-product-mark').show();
                break;
            }
            case '50':
            case '51':
            case '52': {

                $('#fz-product-mark').show();
                break;
            }

            case '60':
            case '61':{

                $('#mt-product-mark').show();
                break;
            }
        }

        form.render();

    })

})